#! /usr/bin/perl
use strict;
use Compress::Zlib;

my $id = $ARGV[0];
my $input = join('', <STDIN>);

if (not defined $id) {
  my $output = Compress::Zlib::memGzip($input);
  if (length($output) < length($input)) {
    print $output,"4pc1", pack("NN", length($input), length($output));
  } else {
    print $input,"4pc1", pack("NN", length($input), 0);
  }
} else {
  print $input, $id, pack("NN", length($input), $ARGV[1]);
}
